/**
 *
 */
$(function () {
    $(document).keyup(function (e) {
        if (e.which == 13) {
            $('#selectBtnEnter').click();
        }
    })
});
var path = '../';
var pageListUrl = path + 'weixin/powerTrade';
var pageUrl = path + 'weixin/';
var btnType = "1";
var equipmentCode = "";
//添加弹窗
var addPanel = null;
var addPanelPicture = null;
// ---------------交互代码begin-----------------
//本页面业务逻辑
var weixin = {
    checkLogic: function (dataObj) {
        var isSubmit = true;
        //TODO 逻辑校验，去掉不必要的:
        //检查表单是否存在错误
        $.each(dataObj, function (key) {
            if (key.indexOf('Err') != -1 && dataObj[key].length > 0) {
                return false;
            }
        });
        return isSubmit;
    }

};
//本页面业务逻辑
var advInfo = {
    checkLogic: function (dataObj, err, fg) {
        advInfo.clear(err);
        console.log(dataObj)
        var result = "";
        var isSubmit = true;
        //TODO 逻辑校验，去掉不必要的:
        result = customUtils.checkLen(dataObj.postionCode, 1, 32, '位置编号');
        if (result.length != 0) {
            err.positionCodeErr = result;
            isSubmit = false;
        }
        $.ajax({
            url: pageUrl + "checkPositionCode",
            type: "POST",
            dataType: "json",
            data: {postionCode: dataObj.postionCode},
            cache: false,
            async: false
        }).done(function (res) {
            if (res.result == '0') {
                err.positionCodeErr = '位置编号不存在';
                isSubmit = false;
            }
        })
        console.log(err)
        //检查表单是否存在错误
        $.each(err, function (key) {
            if (key.indexOf('Err') != -1 && err[key].length > 0) {
                return false;
            }
        });
        return isSubmit;
    },
    clear: function (obj) {
        $.each(obj, function (key) {
            if ($.isArray(obj[key])) {
                obj[key] = [];
            } else {
                obj[key] = "";
            }
        });
    }
};
//绑定列表List---begin----所有的操作都围绕列表展开，新增、更新其他比较独立 
var dataList = new Vue({
    el: "#tradeList",
    data: {
        pageInfo: {},
        //TODO 自定义条件查询---begin--------
        condition: {
            page: 1,
            rows: customUtils.pageSize,
            overDate:"",
            startDate:"",
            equipmentCode: "",
            appId: "",
            subAppId: "",
            mchId: "",
            subMchId: "",
            industry: "",
            mchName: "",
            mchFullName: "",
            subMchFullName: "",
            applyTime: "",
            bindStatus: "",
            totalFee:"",
            goods:"",
            transactionId:"",
            faceCode:"",
            updateTime:"",

            items: [],
            all: false,
            key: "",
            statusOk: "",
            statusNo: "",
            Percentage: "",
            id: "",
            empno: "",
            createdBy: "",
            createdDate: "",
            updatedBy: "",
            updatedDate: "",
            installPhoto: "",
            installDate: "",
            flowRate: "",
            status: "",
        },
        //自定义条件查询---end--------
        selectIds: [],//多选
        showSuccess: false,//false不显示成功提示
        selectedIdx: -1,//保存操作行的索引
        isSearch: false,//init:页面初始化；search:点击查询；paging:点击翻页；changePageSize:改变页面显示条数
        selectedPageSize: customUtils.pageSize//修改页面数据显示条数
    },
    mounted: function () {
        this.getList('init');
    },
    // 在 `methods` 对象中定义方法,如果操作中函数的逻辑比较复杂，必须封装到dictType对象
    methods: {
        selectChkBtn: function (e) {//用于多选事件
            this.selectIds.push($(e.target).val());
        },
        exportStore: function () {
            var self = this;
            var key = self.condition["key"];
            var bindStatus = self.condition["bindStatus"];
            location.href = pageUrl + "exportDetail?bindStatus=" + bindStatus + "&key=" + key;
        },

        //搜索、分页列表
        getList: function (eventSrc) {
            var self = this;
            //改变页面显示条数
            if (eventSrc == "changePageSize") {
                if (this.pageInfo.pageSize != this.selectedPageSize) {
                    this.pageInfo.pageSize = this.selectedPageSize;
                    $('#pagination').jqPaginator('destroy');
                    eventSrc = 'init';//重新绘制控件
                } else {
                    return;
                }
            }
            var param = {"page": 1, "rows": customUtils.pageSize};
            //初始化时无当前页数，后台有默认第1页，每页10条
            if (this.pageInfo != undefined && this.pageInfo.pageNum != undefined) {
                self.condition["page"] = this.pageInfo.pageNum;
                self.condition["rows"] = this.pageInfo.pageSize;
            }
            param["page"] = self.condition["page"];
            param["rows"] = self.condition["rows"];
            param["key"] = self.condition["key"];
            param["bindStatus"] = self.condition["bindStatus"];
            param["startDate"] = self.condition["startDate"];
            param["overDate"] = self.condition["overDate"];
            this.condition.items = [];
            console.log(param)
            //发送请求,第一个参数http对象，第二个是url，第三个是参数，第四个是成功回调，第五个是请求失败回调
            customUtils.post(self, pageListUrl, param, function (response, isSuccess) {
                if (isSuccess == false) {
                    dataList.pageInfo.pages = 0;
                    customUtils.noData('无数据', 0);
                    return;
                }
                dataList.pageInfo = response.body.pagination;
                customUtils.noData('无数据', dataList.pageInfo.pages);
                //页面初始化、搜索时，才需要执行分页控件
                if (eventSrc == 'init' || eventSrc == 'search') {
                    customUtils.paging('#pagination', dataList.pageInfo.pages, customUtils.showPage, function (num) {
                        //当前页码pageNum与将要翻页的页码num不相等才执行，否则为同一页
                        if (dataList.pageInfo.pageNum != num) {
                            dataList.pageInfo.pageNum = num;
                            dataList.getList('paging');
                        }
                    });
                }
            }, function (response) {
                console.log(response);
                dataList.pageInfo.pages = 0;
                customUtils.noData('无数据', 0);
            });
        },
        changeTime:function(elem){
            this.$data.condition[elem.split("-")[0]] = $("#"+elem).val();
        },
        //全选--取消全选方法
        checkAll: function () {
            console.log(this.condition);
            if (this.condition.all) {
                this.condition.all = false;
                $("tbody").find("input[type='checkbox'][name='id']").each(function (i, val) {
                    dataList.condition.items = [];
                });
            } else {
                this.condition.all = true;
                $("tbody").find("input[type='checkbox'][name='id']").each(function (i, val) {
                    dataList.condition.items[i] = val.value;
                });
            }
        }
    }
});
